package com.ofsoft.web.admin.controller;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.ofsoft.web.admin.core.config.WxConfigInfo;
import com.ofsoft.weixin.mp.message.MessageController;
import com.ofsoft.weixin.mp.message.MessageRequest;
import com.ofsoft.weixin.mp.message.MessageResponse;
import com.ofsoft.weixin.mp.message.type.TextMessage;

/**
 * 微信消息处理类
 * 
 * @author OF
 * @date 2018年7月23日
 */
public class WeixinMessageHander extends MessageController {

	@Override
	public MessageResponse textTypeMsg(MessageRequest params) {
		TextMessage msg = new TextMessage();
		String msgContent = (String) params.getRequestParam("Content");
		Record record = Db
				.findFirst(
						"select id, auto_key, content, status, created, updated from of_sys_weixin_auto where is_del = '1' and status='1' and auto_key = ? ",
						msgContent);
		if (record != null) {
			msg.setContent(StringUtils.defaultIfBlank(record.getStr("content"),
					WxConfigInfo.getMsg("weixin_seach_no_info")));
		} else {
			msg.setContent(WxConfigInfo.getMsg("weixin_auto_no_info"));
		}
		return msg;
	}

	@Override
	public MessageResponse subscribe(MessageRequest params) {
		TextMessage msg = new TextMessage();
		msg.setContent(WxConfigInfo.getMsg("weixin_processInFollowEvent"));
		return msg;
	}

	@Override
	public MessageResponse unsubscribe(MessageRequest params) {
		TextMessage msg = new TextMessage();
		msg.setContent(WxConfigInfo.getMsg("weixin_unsubscribe"));
		return msg;
	}

}
